package blancosMikel.controller.servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import blancosMikel.controller.beans.informativaBeans;
import blancosMikel.model.dao.informativaDAO;

/**
 * Servlet implementation class loginErrors
 */
@WebServlet(description = "Maneja los errores de sesion", urlPatterns = { "/loginErrors" })
public class loginErrorsSVR extends HttpServlet {
	private static final long serialVersionUID = 1L;

	informativaBeans info = new informativaBeans();

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public loginErrorsSVR() {
		super();
		System.out.println("SVR.loginErrors----------> Ejecutandose!");
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		System.out.println("SVR.loginErrors----------> doGet");
		int msjError = (int) request.getSession().getAttribute("error");
		try {
			informativaDAO dao = new informativaDAO();
			System.out
					.println("SVR.loginErrors.doGet----------> infoDAO Cargado!");
			
			System.out.println(msjError);
			switch (msjError) {
			case 0:
				request.setAttribute("mensaje", "Error no definido");
				break;
			case 1:
				request.setAttribute("mensaje", "Error de autentificacion!");
				break;
			case 2:
				request.setAttribute("mensaje", "Regresa Pronto!");
				break;
			}

			request.setAttribute("infoBean", dao.selectInfo(info));
			RequestDispatcher rd = request
					.getRequestDispatcher("SEGURIDAD/singIn.jsp");
			rd.forward(request, response);
			System.out
					.println("SVR.loginErrors.doGet----------> forward.singIn.jsp");
		} catch (Exception error) {
			System.out
					.println("SVR.loginErrors.doGet.ErrorCargandoModuloInformativo----------> "
							+ error.getMessage());
			request.setAttribute("mensaje", error.getMessage());
			RequestDispatcher rd = request
					.getRequestDispatcher("SEGURIDAD/singIn.jsp");
			rd.forward(request, response);
			System.out
					.println("SVR.loginErrors.doGet----------> msjErrorforward.singIn.jsp");
		}
	}
}
